import request from './request'
import type { FormData as FormDataType } from '@/store/form'

// 表单相关接口
export const formApi = {
  // 提交表单数据
  submitForm: (data: FormDataType) => {
    return request({
      url: '/api/report-service/wx/service/form/submit',
      method: 'post',
      data
    })
  },

  // 获取表单配置
  getFormConfig: () => {
    return request({
      url: '/api/report-service/wx/service/form/config',
      method: 'get'
    })
  },

  // 验证样本编号是否存在
  validateSampleNumber: (sampleNumber: string) => {
    return request({
      url: '/api/report-service/wx/service/form/validate-sample',
      method: 'post',
      data: { sampleNumber }
    })
  },

  // 上传文件
  uploadFile: (file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    
    return request({
      url: '/api/report-service/wx/service/upload',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

// 微信相关接口
export const wechatApi = {
  // 获取微信JS-SDK配置
  getWechatConfig: (url: string) => {
    return request({
      url: '/api/report-service/wx/service/wechat/config',
      method: 'post',
      data: { url }
    })
  },

  // 获取微信用户信息
  getWechatUserInfo: (code: string) => {
    return request({
      url: '/api/report-service/wx/service/wechat/userinfo',
      method: 'post',
      data: { code }
    })
  }
}